package com.huangliusong.hlsinspringboot.condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

/**
 * 系统属性条件判断
 */
public class OnSystemPropertyCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        //获取元信息
        Map<String, Object> attributes= metadata.getAnnotationAttributes(ConditonalOnSystemProperty.class.getName());
        String propertyName=String.valueOf(attributes.get("name"));
        String propertyValue=String.valueOf(attributes.get("value"));
        String javapropertyVlaue=System.getProperty(propertyName);
        return javapropertyVlaue.equals(propertyValue) ;
    }
}
